<?php
namespace Orx\User\Shared\Mailbox;
/**
 * User MailBox Object
 * To store mailbox connection params
 * 
 * @author Xavier VILAIN
 * @package Orx\User\Shared
 * @property int 		$idusr		User Id
 * @property int 		$boxid		Box Id
 * @property int	 	$shared_id	Id of the shared to object
 * @property int	 	$shared_reference	Reference (has an id) of the shared to object
 * 
 * @method \Orx\User\Mailbox mailbox()
 * 
 */
class Item extends \Fox\Object {
	
	/**
	 * Reverse link to main mailbox
	 * @var string
	 */
	const LINK_MAILBOX = 'mailbox';
	
	/**
	 * User Reference type
	 */
	const USER_REFERENCE = 1;
	
	/**
	 * User Group Reference type
	 */
	const USER_GROUP_REFERENCE = 2;
	
	/**
	 * Get corresponding user
	 * @return \User
	 */
	public function user() {
		if($this->shared_reference == self::USER_REFERENCE) {
			try {
				return new \User($this->shared_id);
			} catch(Fox\Object\Exception\NotExist $e) {
				return new \User();
			}
		}
		return false;
	}
}
\Fox\Dao::infos(Item::className(),new \Fox\Object\Info('user_shared_mailboxes', \Fox\Databases::DB_APP));